package com.lbn.monitor.app;

import android.content.Context;
import android.content.Intent;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.RadioGroup;

import com.free.framework.base.BaseFragmentPagerAdapter;
import com.free.framework.lib.utils.PrefsMgr;
import com.free.framework.ui.FjrAppbar;
import com.google.gson.Gson;
import com.lbn.monitor.R;
import com.lbn.monitor.api.model.Pollutant;
import com.lbn.monitor.app.account.AccountFragment;
import com.lbn.monitor.app.home.HomeFragment;
import com.lbn.monitor.base.AppBaseActivity;
import com.lbn.monitor.util.Constant;
import com.lbn.monitor.util.UPushSdk;
import com.lbn.monitor.widget.Appbar;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import indi.free.widgets.custom_fragment.FragmentTabAdapter;

public class MainActivity extends AppBaseActivity<MainPresenter>implements IMainView {

    @BindView(R.id.radio_group)
    RadioGroup radioGroup;
    @BindView(R.id.view_pager)
    ViewPager viewPager;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
        setAppbar(new Appbar(this)
                .setTitle(getString(R.string.app_name)));
        UPushSdk.instance().pushSwitch(this);
    }


    @Override
    public void onPresenterCreated() {
        super.onPresenterCreated();
        mPresenter.pollutants();
        List<Fragment> fragments = new ArrayList<>();
        fragments.add(HomeFragment.newInstance());
        fragments.add(AccountFragment.newInstance());
        new BaseFragmentPagerAdapter(getSupportFragmentManager(),fragments,viewPager,radioGroup);
//        new FragmentTabAdapter(this, fragments,R.id.replace,radioGroup);
    }


    @Override
    public MainPresenter createPresenter() {
        return new MainPresenter();
    }

    public static void startActivity(Context context){
        context.startActivity(new Intent(context,MainActivity.class));
    }

    @Override
    public void onPollutants(List<Pollutant> data) {
        PrefsMgr.putAndApply(this, Constant.POLLUTANTS,new Gson().toJson(data));
    }
}
